package cn.hinglo.gameclaw.alipay.config;

import com.github.wxpay.sdk.WXPayConfig;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @createTime: 2018/5/18
 * @author: HingLo
 * @description: 微信的配置
 */
public class WeixinConfig implements WXPayConfig {
    private static WeixinConfig weixinConfig = null;
    private byte[] certData;

    private WeixinConfig() throws Exception {
        String certPath = "e:/root/claw/apiclient_cert.p12";
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    /**
     * 通过单例模式来获取对象
     *
     * @return 配置对象实例
     * @throws Exception
     */
    public static WeixinConfig getInstance() throws Exception {
        if (weixinConfig == null) {
            weixinConfig = new WeixinConfig();
        }
        return weixinConfig;
    }

    /**
     * 获取 App ID
     *
     * @return App ID
     */
    @Override
    public String getAppID() {
        return "wxdcc4bf6fca08ed15";
    }

    /**
     * 获取 Mch ID
     *
     * @return Mch ID
     */
    @Override
    public String getMchID() {
        return "1506991051";
    }

    /**
     * 获取 API 密钥
     *
     * @return API密钥
     */
    @Override
    public String getKey() {
        return "04343bd960544e33bf2ce9634c8573b8";
    }

    /**
     * 获取商户证书内容
     *
     * @return 商户证书内容
     */
    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    /**
     * HTTP(S) 连接超时时间，单位毫秒
     *
     * @return
     */
    @Override
    public int getHttpConnectTimeoutMs() {
        return 1000 * 3;
    }

    /**
     * HTTP(S) 读数据超时时间，单位毫秒
     *
     * @return
     */

    @Override
    public int getHttpReadTimeoutMs() {
        return 1000 * 3;
    }

}
